package com.chenj.springbootgrpcserver.interceptor;

import io.grpc.Metadata;
import io.grpc.ServerCall;
import io.grpc.ServerCallHandler;
import io.grpc.ServerInterceptor;
import lombok.extern.slf4j.Slf4j;

/**
 * <p>
 * 拦截类LogGrpcInterceptor.java，每当gRPC请求到来后该类会先执行，这里是将方法名字在日志中打印出来，您可以对请求响应做更详细的处理
 * </p>
 *
 * @since: 2022/8/13 17:45
 * @author: liyi
 */
@Slf4j
public class LogGrpcInterceptor implements ServerInterceptor {
    @Override
    public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> serverCall, Metadata metadata,
                                                                 ServerCallHandler<ReqT, RespT> serverCallHandler) {
        log.info(serverCall.getMethodDescriptor().getFullMethodName());
        return serverCallHandler.startCall(serverCall, metadata);
    }
}

